package com.gitee.ywj1352.leecode;

import org.junit.Test;

/**
 * 测试 链表问题
 *
 * @author wenjie.yang on 2019/10/12.
 */
public class ListDemo {

    //Definition for singly-linked list.
    public class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }

    public ListNode reverseList(ListNode head) {
        ListNode pre = null;
        ListNode n = head;
        while (n != null) {
            //n 才是 每次的head
            n = n.next;
            //这里的head 是重新编排好的 pre
            head.next = pre;
            pre = head;
            //获取到头元素
            head = n;
        }
        return pre;
    }

    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {





        return null;
    }

    @Test
    public void reverseList() {
        ListNode n1 = new ListNode(1);
        ListNode n2 = new ListNode(2);
        ListNode n3 = new ListNode(3);
        ListNode n4 = new ListNode(4);
        n1.next = n2;
        n2.next = n3;
        n3.next = n4;
        ListNode listNode = reverseList(n1);
        System.out.println(listNode);
    }

}
